<?php
require_once '../include/config.php';
require_once '../include/utils.class.php';
require_once '../include/orm.class.php';
$orm = new ORM();

try {
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_admin`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `account` varchar(64) DEFAULT '',
           `password` varchar(64) DEFAULT '',
           `email` varchar(256) DEFAULT '',
           `shop_name` varchar(256) DEFAULT '',
           `contact` text DEFAULT NULL,
           `gmap` varchar(512) DEFAULT '',
           `membership` text DEFAULT NULL,
           `footer` text DEFAULT NULL
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_category`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `name` varchar(256) DEFAULT '',
           `parent_id` int DEFAULT 0,
           `order` double DEFAULT 0,
           `file` varchar(256) DEFAULT ''
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_brand`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `name` varchar(256) DEFAULT '',
           `file` varchar(256) DEFAULT ''
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_tag`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `name` varchar(256) DEFAULT ''
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_product`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE DEFAULT '',
           `status` tinyint(1) DEFAULT 0,
           `name` varchar(256) DEFAULT '',
           `curr` varchar(16) DEFAULT '',
           `price` decimal(10, 2) DEFAULT 0.00,
           `weight` float DEFAULT 0,
           `enabled_member` tinyint(1) DEFAULT 0,
           `enabled_stock` tinyint(1) DEFAULT 0,
           `category_id` int DEFAULT 0,
           `brand_id` int DEFAULT 0,
           `tag_id` varchar(512) DEFAULT '',
           `brief` text,
           `description` text,
           `stock` int DEFAULT 0,
           `stock_alert` int DEFAULT 0,
           `alert__` tinyint(1) DEFAULT 0,
           `sold__` int DEFAULT 0
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_product_attr`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `product_track_id` varchar(16) DEFAULT '',
           `name` varchar(256) DEFAULT ''
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_product_attr_opt`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `product_track_id` varchar(16) DEFAULT '',
           `product_attr_id` int DEFAULT 0,
           `name` varchar(256) DEFAULT '',
           `file` varchar(256) DEFAULT ''
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_product_obj`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `product_track_id` varchar(16) DEFAULT '',
           `attr_opt_id` varchar(256) DEFAULT '',
           `attr_opt_code` varchar(512) DEFAULT '',
           `stock` int DEFAULT 0,
           `stock_alert` int DEFAULT 0,
           `price` decimal(10, 2) DEFAULT 0.00
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_product_img`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `product_track_id` varchar(16) DEFAULT '',
           `file` varchar(256) DEFAULT '',
           `is_default` tinyint(1) DEFAULT 0
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_purchase`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `product_id` int DEFAULT 0,
           `customer_id` int DEFAULT 0,
           `order_id` int DEFAULT 0,
           `name` varchar(256) DEFAULT '',
           `curr` varchar(16) DEFAULT '',
           `price` decimal(10, 2) DEFAULT 0.00,
           `weight` float DEFAULT 0,
           `quantity` int,
           `total` decimal(10, 2) DEFAULT 0.00,
           `attr_opt_id` varchar(256) DEFAULT '',
           `attr_opt_code` varchar(512) DEFAULT ''
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_special`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `product_id` int DEFAULT 0,
           `old_price` decimal(10, 2) DEFAULT 0.00,
           `new_price` decimal(10, 2) DEFAULT 0.00,
           `from` date DEFAULT '0000-00-00',
           `to` date DEFAULT '0000-00-00'
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_order`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `date` date DEFAULT '0000-00-00',
           `ship_date` date DEFAULT '0000-00-00',
           `ship_track` varchar(128) DEFAULT '',
           `customer_id` int DEFAULT 0,
           `order_number` varchar(32) DEFAULT '',
           `is_paid` tinyint(1) DEFAULT 0,
           `is_cancel` tinyint(1) DEFAULT 0,
           `curr` varchar(16) DEFAULT '',
           `total` decimal(10, 2) DEFAULT 0.00,
           `comment` text,
           `payment_id` int DEFAULT 0,
           `payment_name` varchar(256) DEFAULT '',
           `payment_code` varchar(16) DEFAULT '',
           `delivery_id` int DEFAULT 0,
           `delivery_name` varchar(256) DEFAULT '',
           `delivery_subtotal` decimal(10, 2) DEFAULT 0.00,
           `first_name` varchar(64) DEFAULT '',
           `last_name` varchar(64) DEFAULT '',
           `address1` varchar(256) DEFAULT '',
           `address2` varchar(256) DEFAULT '',
           `city` varchar(64) DEFAULT '',
           `country` varchar(64) DEFAULT '',
           `zip` varchar(64) DEFAULT '',
           `phone` varchar(64) DEFAULT '',
           `email` varchar(64) DEFAULT ''
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_customer`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE DEFAULT '',
           `member_id` int DEFAULT 0,
           `account` varchar(64) UNIQUE DEFAULT '',
           `password` varchar(64) DEFAULT '',
           `salt` varchar(64) DEFAULT '',
           `reset_key` varchar(64) DEFAULT '',
           `reg_date` date DEFAULT '0000-00-00',
           `last_login` date DEFAULT '0000-00-00',
           `first_name` varchar(64) DEFAULT '',
           `last_name` varchar(64) DEFAULT '',
           `phone` varchar(64) DEFAULT '',
           `status` tinyint(1) DEFAULT 0,
           `ip` varchar(64) DEFAULT '',
           `ip_place` varchar(64) DEFAULT '',
           `spent__` decimal(10, 2) DEFAULT 0.00
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_customer_addr`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `customer_id` int DEFAULT 0,
           `first_name` varchar(64) DEFAULT '',
           `last_name` varchar(64) DEFAULT '',
           `address1` varchar(256) DEFAULT '',
           `address2` varchar(256) DEFAULT '',
           `city` varchar(64) DEFAULT '',
           `country` varchar(64) DEFAULT '',
           `zip` varchar(64) DEFAULT '',
           `phone` varchar(64) DEFAULT '',
           `email` varchar(64) DEFAULT '',
           `is_default` tinyint(1) DEFAULT 0
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_membership`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `title` varchar(256) DEFAULT '',
           `total_spent` decimal(10, 2) DEFAULT 0.00,
           `discount` float DEFAULT 0.00
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_currency`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `title` varchar(16) DEFAULT '',
           `display_name` varchar(256) DEFAULT '',
           `dollar_symbol` varchar(16) DEFAULT '',
           `rate` decimal(10, 2) DEFAULT 0.00,
           `is_default` tinyint(1) DEFAULT 0
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_mthd_payment`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `code` varchar(16) DEFAULT '',
           `account` varchar(256) DEFAULT '',
           `title` varchar(256) DEFAULT '',
           `description` text,
           `curr_id` varchar(256) DEFAULT '',
           `status` tinyint(1) DEFAULT 0
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_mthd_delivery`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `title` varchar(256) DEFAULT '',
           `description` text,
           `curr` varchar(16) DEFAULT '',
           `min_weight` float DEFAULT 0.00,
           `min_price` decimal(10, 2) DEFAULT 0.00,
           `next_price` decimal(10, 2) DEFAULT 0.00,
           `track_link` varchar(512) DEFAULT '',
           `status` tinyint(1) DEFAULT 0
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_article`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `tag_id` text,
           `title` varchar(512) DEFAULT '',
           `content` text,
           `date` datetime DEFAULT '0000-00-00 00:00:00',
           `visited__` int DEFAULT 0
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
  $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_hm_gallery`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `parent_id` int DEFAULT 0,
           `order` double DEFAULT 0,
           `url` varchar(256) DEFAULT '',
           `txt` text DEFAULT NULL,
           `file` varchar(256) DEFAULT ''
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
    $sql = "CREATE TABLE IF NOT EXISTS `pb_ecom_hm_banner`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `parent_id` int DEFAULT 0,
           `order` double DEFAULT 0,
           `url` varchar(256) DEFAULT '',
           `txt` text DEFAULT NULL,
           `file` varchar(256) DEFAULT ''
          ) ENGINE=MYISAM;";
  $orm->exec($sql);
  
//  $pass = md5(123456);
//  $sql = "INSERT INTO pb_ecom_admin values (NULL, 'admin', '$pass', '', '')";
//  $orm->exec($sql);
} catch (PDOException $e) {
  Utils::dump($e);
}
?>